<html>
<head>
<style type="text/css">
/**
 * HTML5 ✰ Boilerplate
 *
 * style.css contains a reset, font normalization and some base styles.
 *
 * Credit is left where credit is due.
 * Much inspiration was taken from these projects:
 * - yui.yahooapis.com/2.8.1/build/base/base.css
 * - camendesign.com/design/
 * - praegnanz.de/weblog/htmlcssjs-kickstart
 */


/**
 * html5doctor.com Reset Stylesheet (Eric Meyer's Reset Reloaded + HTML5 baseline)
 * v1.6.1 2010-09-17 | Authors: Eric Meyer & Richard Clark
 * html5doctor.com/html-5-reset-stylesheet/
 */

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

sup { vertical-align: super; }
sub { vertical-align: sub; }

article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
  display: block;
}

blockquote, q { quotes: none; }

blockquote:before, blockquote:after,
q:before, q:after { content: ""; content: none; }

ins { background-color: #ff9; color: #000; text-decoration: none; }

mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; }

del { text-decoration: line-through; }

abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; }

table { border-collapse: collapse; border-spacing: 0; }

hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; }

input, select { vertical-align: middle; }


/**
 * Font normalization inspired by YUI Library's fonts.css: developer.yahoo.com/yui/
 */

body { font:13px/1.231 sans-serif; *font-size:small; } /* Hack retained to preserve specificity */
select, input, textarea, button { font:99% sans-serif; }

/* Normalize monospace sizing:
   en.wikipedia.org/wiki/MediaWiki_talk:Common.css/Archive_11#Teletype_style_fix_for_Chrome */
pre, code, kbd, samp { font-family: monospace, sans-serif; }

em,i { font-style: italic; }
b,strong { font-weight: bold; }

</style>
<style type="text/css">

/* Flexible box model classes */
/* Taken from Alex Russell http://infrequently.org/2009/08/css-3-progress/ */
 
.hbox {
	display: -webkit-box;
	-webkit-box-orient: horizontal;
	-webkit-box-align: stretch;
 
	display: -moz-box;
	-moz-box-orient: horizontal;
	-moz-box-align: stretch;
 
	display: box;
	box-orient: horizontal;
	box-align: stretch;
}
 
.hbox > * {
	-webkit-box-flex: 0;
	-moz-box-flex: 0;
	box-flex: 0;
}
 
.vbox {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-box-align: stretch;
 
	display: -moz-box;
	-moz-box-orient: vertical;
	-moz-box-align: stretch;
 
	display: box;
	box-orient: vertical;
	box-align: stretch;
}
 
.vbox > * {
	-webkit-box-flex: 0;
	-moz-box-flex: 0;
	box-flex: 0;
}
  
.reverse {
	-webkit-box-direction: reverse;
	-moz-box-direction: reverse;
	box-direction: reverse;
}
 
.box-flex0 {
	-webkit-box-flex: 0;
	-moz-box-flex: 0;
	box-flex: 0;
}
 
.box-flex1, .box-flex {
	-webkit-box-flex: 1;
	-moz-box-flex: 1;
	box-flex: 1;
}
 
.box-flex2 {
	-webkit-box-flex: 2;
	-moz-box-flex: 2;
	box-flex: 2;
}
 
.box-group1 {
	-webkit-box-flex-group: 1;
	-moz-box-flex-group: 1;
	box-flex-group: 1;
}
 
.box-group2 {
	-webkit-box-flex-group: 2;
	-moz-box-flex-group: 2;
	box-flex-group: 2;
}
 
.start {
	-webkit-box-pack: start;
	-moz-box-pack: start;
	box-pack: start;
}
 
.end {
	-webkit-box-pack: end;
	-moz-box-pack: end;
	box-pack: end;
}
 
.center {
	-webkit-box-pack: center;
	-moz-box-pack: center;
	box-pack: center;
}

</style>
<style type="text/css">
/**
 * Primary styles
 *
 * Author: IPython Development Team
 */


body {
    overflow: hidden;
}

span#save_widget {
    padding: 5px;
    margin: 0px 0px 0px 300px;
    display:inline-block;
}

span#notebook_name {
    height: 1em;
    line-height: 1em;
    padding: 3px;
    border: none;
    font-size: 146.5%;
}

.ui-menubar-item .ui-button .ui-button-text {
    padding: 0.4em 1.0em;
    font-size: 100%;
}

.ui-menu {
  -moz-box-shadow:    0px 6px 10px -1px #adadad;
  -webkit-box-shadow: 0px 6px 10px -1px #adadad;
  box-shadow:         0px 6px 10px -1px #adadad;
}

.ui-menu .ui-menu-item a {
    border: 1px solid transparent;
    padding: 2px 1.6em;
}

.ui-menu .ui-menu-item a.ui-state-focus {
    margin: 0;
}

.ui-menu hr {
    margin: 0.3em 0;
}

#menubar_container {
    position: relative;
}

#notification {
    position: absolute;
    right: 3px;
    top: 3px;
    height: 25px;
    padding: 3px 6px;
    z-index: 10;
}

#toolbar {
    padding: 3px 15px;
}

#cell_type {
    font-size: 85%;
}


div#main_app {
    width: 100%;
    position: relative;
}

span#quick_help_area {
    position: static;
    padding: 5px 0px;
    margin: 0px 0px 0px 0px;
}

.help_string {
    float: right;
    width: 170px;
    padding: 0px 5px;
    text-align: left;
    font-size: 85%;
}

.help_string_label {
    float: right;
    font-size: 85%;
}

div#notebook_panel {
    margin: 0px 0px 0px 0px;
    padding: 0px;
}

div#notebook {
    overflow-y: scroll;
    overflow-x: auto;
    width: 100%;
    /* This spaces the cell away from the edge of the notebook area */
    padding: 5px 5px 15px 5px;
    margin: 0px;
    background-color: white;
}

div#pager_splitter {
    height: 8px;
}

div#pager {
    padding: 15px;
    overflow: auto;
    display: none;
}

div.ui-widget-content {
    border: 1px solid #aaa;
    outline: none;
}

.cell {
    border: 1px solid transparent;
}

div.cell {
    width: 100%;
    padding: 5px 5px 5px 0px;
    /* This acts as a spacer between cells, that is outside the border */
    margin: 2px 0px 2px 0px;
}

div.code_cell {
    background-color: white;
}

/* any special styling for code cells that are currently running goes here */
div.code_cell.running {
}

div.prompt {
    /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */
    width: 11ex;
    /* This 0.4em is tuned to match the padding on the CodeMirror editor. */
    padding: 0.4em;
    margin: 0px;
    font-family: monospace;
    text-align:right;
}

div.input {
    page-break-inside: avoid;
}

/* input_area and input_prompt must match in top border and margin for alignment */
div.input_area {
    color: black;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #f7f7f7;
}

div.input_prompt {
    color: navy;
    border-top: 1px solid transparent;
}

div.output_wrapper {
    /* This is a spacer between the input and output of each cell */
    margin-top: 5px;
    margin-left: 5px;
    /* FF needs explicit width to stretch */
    width: 100%;
    /* this position must be relative to enable descendents to be absolute within it */
    position: relative;
}

/* class for the output area when it should be height-limited */
div.output_scroll {
  /* ideally, this would be max-height, but FF barfs all over that */
  height: 24em;
  /* FF needs this *and the wrapper* to specify full width, or it will shrinkwrap */
  width: 100%;
  
  overflow: auto;
  border-radius: 3px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8);
}

/* output div while it is collapsed */
div.output_collapsed {
  margin-right: 5px;
}

div.out_prompt_overlay {
  height: 100%;
  padding: 0px;
  position: absolute;
  border-radius: 3px;
}

div.out_prompt_overlay:hover {
  /* use inner shadow to get border that is computed the same on WebKit/FF */
  box-shadow: inset 0 0 1px #000;
  background: rgba(240, 240, 240, 0.5);
}

div.output_prompt {
    color: darkred;
    /* 5px right shift to account for margin in parent container */
    margin: 0 5px 0 -5px;
}

/* This class is the outer container of all output sections. */
div.output_area {
    padding: 0px;
    page-break-inside: avoid;
}

/* This class is for the output subarea inside the output_area and after
   the prompt div. */
div.output_subarea {
    padding: 0.4em 0.4em 0.4em 0.4em;
}

/* The rest of the output_* classes are for special styling of the different
   output types */

/* all text output has this class: */
div.output_text {
    text-align: left;
    color: black;
    font-family: monospace;
}

/* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */
div.output_stream {
    padding-top: 0.0em;
    padding-bottom: 0.0em;
}
div.output_stdout {
}
div.output_stderr {
    background: #fdd; /* very light red background for stderr */
}

div.output_latex {
    text-align: left;
    color: black;
}

div.output_html {
}

div.output_png {
}

div.output_jpeg {
}

div.text_cell {
    background-color: white;
    padding: 5px 5px 5px 5px;
}

div.text_cell_input {
    color: black;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #f7f7f7;
}

div.text_cell_render {
    font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
    outline: none;
    resize: none;
    width:  inherit;
    border-style: none;
    padding: 5px;
    color: black;
}

/* The following gets added to the <head> if it is detected that the user has a
 * monospace font with inconsistent normal/bold/italic height.  See
 * notebookmain.js.  Such fonts will have keywords vertically offset with
 * respect to the rest of the text.  The user should select a better font. 
 * See: https://github.com/ipython/ipython/issues/1503
 *
 * .CodeMirror span {
 *      vertical-align: bottom;
 * }
 */

.CodeMirror {
    line-height: 1.231;  /* Changed from 1em to our global default */
}

.CodeMirror-scroll {
    height: auto;     /* Changed to auto to autogrow */
    /*  The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/
    /*  We have found that if it is visible, vertical scrollbars appear with font size changes.*/
    overflow-y: hidden;
    overflow-x: auto; /* Changed from auto to remove scrollbar */
}

/* CSS font colors for translated ANSI colors. */


.ansiblack {color: black;}
.ansired {color: darkred;}
.ansigreen {color: darkgreen;}
.ansiyellow {color: brown;}
.ansiblue {color: darkblue;}
.ansipurple {color: darkviolet;}
.ansicyan {color: steelblue;}
.ansigrey {color: grey;}
.ansibold {font-weight: bold;}

.completions {
    position: absolute;
    z-index: 10;
    overflow: hidden;
    border: 1px solid grey;
}

.completions select {
    background: white;
    outline: none;
    border: none;
    padding: 0px;
    margin: 0px;
    overflow: auto;
    font-family: monospace;
}

option.context {
  background-color: #DEF7FF;
}
option.introspection {
  background-color: #EBF4EB;
}

/*fixed part of the completion*/
.completions p b {
    font-weight:bold;
}

.completions p {
    background: #DDF;
    /*outline: none;
    padding: 0px;*/
    border-bottom: black solid 1px;
    padding: 1px;
    font-family: monospace;
}

pre.dialog {
    background-color: #f7f7f7;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 0.4em;
    padding-left: 2em;
}

p.dialog {
    padding : 0.2em;
}

.shortcut_key {
    display: inline-block;
    width: 15ex;
    text-align: right;
    font-family: monospace;
}

.shortcut_descr {
}

/* Word-wrap output correctly.  This is the CSS3 spelling, though Firefox seems
   to not honor it correctly.  Webkit browsers (Chrome, rekonq, Safari) do.
 */
pre, code, kbd, samp { white-space: pre-wrap; }

#fonttest {
    font-family: monospace;
}

.js-error {
    color: darkred;
}
</style>
<style type="text/css">
.rendered_html {color: black;}
.rendered_html em {font-style: italic;}
.rendered_html strong {font-weight: bold;}
.rendered_html u {text-decoration: underline;}
.rendered_html :link { text-decoration: underline }
.rendered_html :visited { text-decoration: underline }
.rendered_html h1 {font-size: 197%; margin: .65em 0; font-weight: bold;}
.rendered_html h2 {font-size: 153.9%; margin: .75em 0; font-weight: bold;}
.rendered_html h3 {font-size: 123.1%; margin: .85em 0; font-weight: bold;}
.rendered_html h4 {font-size: 100% margin: 0.95em 0; font-weight: bold;}
.rendered_html h5 {font-size: 85%; margin: 1.5em 0; font-weight: bold;}
.rendered_html h6 {font-size: 77%; margin: 1.65em 0; font-weight: bold;}
.rendered_html ul {list-style:disc; margin: 1em 2em;}
.rendered_html ul ul {list-style:square; margin: 0em 2em;}
.rendered_html ul ul ul {list-style:circle; margin-left: 0em 2em;}
.rendered_html ol {list-style:upper-roman; margin: 1em 2em;}
.rendered_html ol ol {list-style:upper-alpha; margin: 0em 2em;}
.rendered_html ol ol ol {list-style:decimal; margin: 0em 2em;}
.rendered_html ol ol ol ol {list-style:lower-alpha; margin 0em 2em;}
.rendered_html ol ol ol ol ol {list-style:lower-roman; 0em 2em;}

.rendered_html hr {
    color: black;
    background-color: black;
}

.rendered_html pre {
    margin: 1em 2em;
}

.rendered_html blockquote {
    margin: 1em 2em;
}

.rendered_html table {
    border: 1px solid black;
    border-collapse: collapse;
    margin: 1em 2em;
}

.rendered_html td {
    border: 1px solid black;
    text-align: left;
    vertical-align: middle;
    padding: 4px;
}

.rendered_html th {
    border: 1px solid black;
    text-align: left;
    vertical-align: middle;
    padding: 4px;
    font-weight: bold;
}

.rendered_html tr {
    border: 1px solid black;
}    

.rendered_html p + p {
    margin-top: 1em;
}


</style>
<style type="text/css">
/* Overrides of notebook CSS for static HTML export

*/
body {
  overflow: visible;
  padding: 8px;
}
.input_area {
  padding: 0.4em;
}

</style>
<meta charset="UTF-8">
<style type="text/css">
.highlight .hll { background-color: #ffffcc }
.highlight  { background: #f8f8f8; }
.highlight .c { color: #408080; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #008000; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #808080 } /* Generic.Output */
.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008000 } /* Keyword.Pseudo */
.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #B00040 } /* Keyword.Type */
.highlight .m { color: #666666 } /* Literal.Number */
.highlight .s { color: #BA2121 } /* Literal.String */
.highlight .na { color: #7D9029 } /* Name.Attribute */
.highlight .nb { color: #008000 } /* Name.Builtin */
.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.highlight .no { color: #880000 } /* Name.Constant */
.highlight .nd { color: #AA22FF } /* Name.Decorator */
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0000FF } /* Name.Function */
.highlight .nl { color: #A0A000 } /* Name.Label */
.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #19177C } /* Name.Variable */
.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #666666 } /* Literal.Number.Float */
.highlight .mh { color: #666666 } /* Literal.Number.Hex */
.highlight .mi { color: #666666 } /* Literal.Number.Integer */
.highlight .mo { color: #666666 } /* Literal.Number.Oct */
.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
.highlight .sc { color: #BA2121 } /* Literal.String.Char */
.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.highlight .sx { color: #008000 } /* Literal.String.Other */
.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
.highlight .ss { color: #19177C } /* Literal.String.Symbol */
.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #19177C } /* Name.Variable.Class */
.highlight .vg { color: #19177C } /* Name.Variable.Global */
.highlight .vi { color: #19177C } /* Name.Variable.Instance */
.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
</style>
<script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" type="text/javascript">

</script>
<script type="text/javascript">
init_mathjax = function() {
    if (window.MathJax) {
        // MathJax loaded
        MathJax.Hub.Config({
            tex2jax: {
                inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
            },
            displayAlign: 'left', // Change this to 'center' to center equations.
            "HTML-CSS": {
                styles: {'.MathJax_Display': {"margin": 0}}
            }
        });
        MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
    }
}
init_mathjax();
</script>
</head>
<body>
<div class="text_cell_render border-box-sizing rendered_html">
<h1>
  AutoNetkit Tutorial
</h1>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  About this Tutorial
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>This tutorial has been written using the <a href="http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html">IPython Notebook system</a>, which allows this tutorial to be run interactively.</p>
<p>The best way to do so is to check out the AutoNetkit project from GitHub:</p>
<pre><code>git clone https://github.com/sk2/autonetkit
</code></pre>
<p>and run the notebook server from the examples directory:</p>
<pre><code>$ cd autonetkit/examples
$ ipython notebook
</code></pre>
<p>This will bring up a webpage, allowing you to choose the tutorial notebook. You can then modify and execute the code using the run options under the "Cell" menu, the "Run" toolbar button, or by pressing Ctrl+Enter.</p>
<p>Please note this is a growing work in progress. It will be split into multiple tutorials in the future. To contribute, please fork the AutoNetkit GitHub project, modify the tutorial, and submit a pull request with your changes.</p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Installing AutoNetkit
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>Install AutoNetkit by following the instructions <a href="http://autonetkit.org/installation.html">here</a></p>
<p>If all goes successfully, you should be able to import autonetkit from the Python intepreter.</p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  AutoNetkit Design Process
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>The below flowchart provides an overview of the design process in AutoNetkit.</p>
<ol>
<li>The input file is loaded into the Abstract Network Model.</li>
<li>This is stored as G_in.</li>
<li>Overlay graphs are created by the user to represent services and protocols.</li>
<li>The Compile module condenses the overlay graphs into a single resource database, the Network Information Database. This includes defining the template(s) to be used.</li>
</ol>
<p><img alt="" src="files/images/flowchart_anm.png" /></p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Visualisation Server
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>The first step is to enable the visualisation server.
At a command prompt, run</p>
<pre><code>$ank_webserver
</code></pre>
<p>You should get the following message:</p>
<pre><code>Visualisation server started
</code></pre>
<p>We can test that AutoNetkit can send to the webserver:</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[1]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">()</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stderr">
<pre><span class="ansigrey">INFO</span> Visualisation server running
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Designing a Network
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>In this tutorial we use a graphml file created using the yEd graph editor, available at <a href="http://www.yworks.com/en/products_yed_about.html">http://www.yworks.com/en/products_yed_about.html</a>.</p>
<p>You can download yEd to modify the graphml file, and rerun the code to view the changes.</p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can now import the graphml load module to import a graphml file, and the Abstract Network Model to store our overlay networks.</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[2]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit.load.graphml</span> <span class="kn">as</span> <span class="nn">graphml</span>
<span class="kn">import</span> <span class="nn">autonetkit.anm</span>

<span class="n">anm</span> <span class="o">=</span>  <span class="n">autonetkit</span><span class="o">.</span><span class="n">ANM</span><span class="p">()</span>
<span class="c">#input_graph = graphml.load_graphml(&quot;small_internet.graphml&quot;)</span>
<span class="n">input_graph</span> <span class="o">=</span> <span class="n">graphml</span><span class="o">.</span><span class="n">load_graphml</span><span class="p">(</span><span class="s">&quot;singleas.graphml&quot;</span><span class="p">)</span>
<span class="n">g_in</span> <span class="o">=</span> <span class="n">anm</span><span class="o">.</span><span class="n">initialise_graph</span><span class="p">(</span><span class="n">input_graph</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>Create the Physical Graph</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[3]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">g_phy</span> <span class="o">=</span> <span class="n">anm</span><span class="p">[</span><span class="s">&#39;phy&#39;</span><span class="p">]</span>
<span class="n">g_phy</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">g_in</span><span class="p">,</span> <span class="n">retain</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;label&#39;</span><span class="p">,</span> <span class="s">&#39;device_type&#39;</span><span class="p">,</span> <span class="s">&#39;asn&#39;</span><span class="p">,</span> <span class="s">&#39;platform&#39;</span><span class="p">,</span> <span class="s">&#39;host&#39;</span><span class="p">,</span> <span class="s">&#39;syntax&#39;</span><span class="p">])</span>
<span class="n">g_phy</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(</span><span class="n">g_in</span><span class="o">.</span><span class="n">edges</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s">&quot;physical&quot;</span><span class="p">),</span> <span class="n">retain</span><span class="o">=</span><span class="s">&#39;edge_id&#39;</span><span class="p">)</span>
<span class="n">g_phy</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">g_phy</span><span class="p">,</span> <span class="n">syntax</span><span class="o">=</span><span class="s">&quot;quagga&quot;</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/phy.png" /></p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>The OSPF graph is constructed from routers in the physical graph, and edges in the physical graph, that are within an AS.</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[4]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">g_ospf</span> <span class="o">=</span> <span class="n">anm</span><span class="o">.</span><span class="n">add_overlay</span><span class="p">(</span><span class="s">&quot;ospf&quot;</span><span class="p">,</span> <span class="n">g_in</span><span class="o">.</span><span class="n">routers</span><span class="p">())</span>
<span class="n">g_ospf</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">((</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">g_in</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">src</span><span class="o">.</span><span class="n">asn</span> <span class="o">==</span> <span class="n">e</span><span class="o">.</span><span class="n">dst</span><span class="o">.</span><span class="n">asn</span><span class="p">),</span> <span class="n">retain</span><span class="o">=</span><span class="s">&#39;edge_id&#39;</span><span class="p">)</span>
<span class="n">g_ospf</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">area</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="c"># set defaults</span>
<span class="n">g_ospf</span><span class="o">.</span><span class="n">update_edges</span><span class="p">(</span><span class="n">area</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/ospf.png" /></p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now create the BGP overlays, also using the routers. This is a directed graph.</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[5]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">g_bgp</span> <span class="o">=</span> <span class="n">anm</span><span class="o">.</span><span class="n">add_overlay</span><span class="p">(</span><span class="s">&quot;bgp&quot;</span><span class="p">,</span> <span class="n">g_in</span><span class="o">.</span><span class="n">routers</span><span class="p">(),</span> <span class="n">directed</span> <span class="o">=</span> <span class="bp">True</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/bgp.png" /></p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[6]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">g_bgp</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">((</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">g_in</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">src</span><span class="o">.</span><span class="n">asn</span> <span class="o">!=</span> <span class="n">e</span><span class="o">.</span><span class="n">dst</span><span class="o">.</span><span class="n">asn</span><span class="p">),</span> 
    <span class="n">bidirectional</span> <span class="o">=</span> <span class="bp">True</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="s">&#39;ebgp&#39;</span><span class="p">,</span> <span class="n">retain</span><span class="o">=</span><span class="s">&#39;edge_id&#39;</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/ebgp.png" /></p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[7]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">g_bgp</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(((</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">g_bgp</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">g_bgp</span> 
    <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">asn</span> <span class="o">==</span> <span class="n">t</span><span class="o">.</span><span class="n">asn</span> <span class="ow">and</span> <span class="n">s</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">t</span><span class="p">),</span> <span class="nb">type</span> <span class="o">=</span> <span class="s">&#39;ibgp&#39;</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/ibgp.png" /></p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[8]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit.ank_messaging</span> <span class="kn">as</span> <span class="nn">ank_messaging</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Highlighting nodes and edges
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can use the highlight function to highlight nodes and edges in the visualization.</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[9]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">asn</span> <span class="o">=</span> <span class="mi">30</span> <span class="c"># change me</span>
<span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">n</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">g_bgp</span> <span class="k">if</span> <span class="n">n</span><span class="o">.</span><span class="n">asn</span> <span class="o">==</span> <span class="n">asn</span><span class="p">]</span>
<span class="n">edges</span> <span class="o">=</span> <span class="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">g_bgp</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">dst</span><span class="o">.</span><span class="n">asn</span> <span class="o">==</span> <span class="n">asn</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s">&#39;ebgp&#39;</span><span class="p">]</span>
<span class="n">ank_messaging</span><span class="o">.</span><span class="n">highlight</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Using NetworkX for Graph Analysis
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can use NetworkX Algorithms such as shortest path. </p>
<ol>
<li>First we need to unwrap the graph to access the underlying NetworkX graph. </li>
<li>We can then perform functions, which return a list of nodes.</li>
<li>We turn this list of nodes on the path into a list of edges, eg [a, b, c, d] -&gt; [(a, b), (b, c), (c, d)]</li>
<li>We then use the ANK selection function to convert this list to edges</li>
<li>We use the highlight function of the messaging module to send it to the webservice.</li>
</ol>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[10]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">autonetkit.ank_utils</span> <span class="kn">import</span> <span class="n">unwrap_graph</span><span class="p">,</span> <span class="n">unwrap_nodes</span>

<span class="kn">import</span> <span class="nn">networkx</span> <span class="kn">as</span> <span class="nn">nx</span>
<span class="n">graph</span> <span class="o">=</span> <span class="n">unwrap_graph</span><span class="p">(</span><span class="n">g_phy</span><span class="p">)</span>

<span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">n</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">graph</span><span class="p">]</span>
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">choice</span>

<span class="n">src</span> <span class="o">=</span> <span class="n">choice</span><span class="p">(</span><span class="n">nodes</span><span class="p">)</span>
<span class="n">dst</span> <span class="o">=</span> <span class="n">choice</span><span class="p">(</span><span class="n">nodes</span><span class="p">)</span>
<span class="c">#(src, dst) = (&#39;as100r1&#39;, &#39;as1r1&#39;)</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">shortest_path</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">)</span>

<span class="n">ebunch</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">path</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span>
<span class="n">edges</span> <span class="o">=</span> <span class="p">[</span><span class="n">g_phy</span><span class="o">.</span><span class="n">edge</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="ow">in</span> <span class="n">ebunch</span><span class="p">]</span>
<span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">]</span>
<span class="n">ank_messaging</span><span class="o">.</span><span class="n">highlight</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/spf.png" /></p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can also use other graph algorithms, such as the Minimum Spanning Tree.</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[11]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">graph</span> <span class="o">=</span> <span class="n">unwrap_graph</span><span class="p">(</span><span class="n">g_ospf</span><span class="p">)</span>
<span class="n">T</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">minimum_spanning_tree</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span>
<span class="n">edges</span> <span class="o">=</span> <span class="p">[</span><span class="n">g_phy</span><span class="o">.</span><span class="n">edge</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="ow">in</span>  <span class="n">T</span><span class="o">.</span><span class="n">edges</span><span class="p">()]</span>
<span class="n">ank_messaging</span><span class="o">.</span><span class="n">highlight</span><span class="p">([],</span> <span class="n">edges</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/mst.png" /></p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>Now let's perform using the edge weight.</p>
<p>Since we are using an iBGP graph, it makes sense to use a larger network than the small_internet, which has at most 4 nodes per AS.</p>
<p>Another network to use would be singleas.graphml to do so, change the first cell above, and rerun the code.</p>
<p>We want to copy across the edge attribute <em>ospf_cost</em> from the input graph, and store it as the <em>cost</em> attribute on the ospf graph.</p>
<p>Since the underlying data structure is NetworkX, these attributes will be present when we unwrap the graph.</p>
<p>We can now add the 'weight' parameter to the MST function call. The rest of the code proceeds as before.</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[12]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit.ank</span> <span class="kn">as</span> <span class="nn">ank_utils</span>
<span class="n">ank_utils</span><span class="o">.</span><span class="n">copy_edge_attr_from</span><span class="p">(</span><span class="n">g_in</span><span class="p">,</span> <span class="n">g_ospf</span><span class="p">,</span> <span class="s">&quot;ospf_cost&quot;</span><span class="p">,</span> <span class="n">dst_attr</span><span class="o">=</span><span class="s">&quot;cost&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>

<span class="n">graph</span> <span class="o">=</span> <span class="n">unwrap_graph</span><span class="p">(</span><span class="n">g_ospf</span><span class="p">)</span>

<span class="n">T</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">minimum_spanning_tree</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">weight</span> <span class="o">=</span> <span class="s">&#39;cost&#39;</span><span class="p">)</span>
<span class="n">edges</span> <span class="o">=</span> <span class="p">[</span><span class="n">g_phy</span><span class="o">.</span><span class="n">edge</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="ow">in</span>  <span class="n">T</span><span class="o">.</span><span class="n">edges</span><span class="p">()]</span>  
<span class="n">ank_messaging</span><span class="o">.</span><span class="n">highlight</span><span class="p">([],</span> <span class="n">edges</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/mst_weighted.png" /></p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[13]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">asn</span> <span class="o">=</span> <span class="mi">20</span>
<span class="n">nbunch</span> <span class="o">=</span> <span class="n">unwrap_nodes</span><span class="p">(</span><span class="n">g_bgp</span><span class="o">.</span><span class="n">nodes</span><span class="p">(</span><span class="n">asn</span><span class="o">=</span><span class="n">asn</span><span class="p">))</span>

<span class="n">graph_bgp</span> <span class="o">=</span> <span class="n">unwrap_graph</span><span class="p">(</span><span class="n">g_bgp</span><span class="p">)</span>
<span class="n">bgp_neighbors</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">node_boundary</span><span class="p">(</span><span class="n">graph_bgp</span><span class="p">,</span> <span class="n">nbunch</span><span class="p">)</span>
<span class="n">ank_messaging</span><span class="o">.</span><span class="n">highlight</span><span class="p">(</span><span class="n">bgp_neighbors</span><span class="p">,</span> <span class="p">[])</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>Using costs for SPF</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[14]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">n</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">graph</span><span class="p">]</span>
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">choice</span>
<span class="n">graph</span> <span class="o">=</span> <span class="n">unwrap_graph</span><span class="p">(</span><span class="n">g_ospf</span><span class="p">)</span>

<span class="n">src</span> <span class="o">=</span> <span class="n">choice</span><span class="p">(</span><span class="n">nodes</span><span class="p">)</span>
<span class="n">dst</span> <span class="o">=</span> <span class="n">choice</span><span class="p">(</span><span class="n">nodes</span><span class="p">)</span>
<span class="c">#(src, dst) = (&#39;r8&#39;, &#39;r1&#39;)</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">shortest_path</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">,</span> <span class="n">weight</span> <span class="o">=</span> <span class="s">&#39;cost&#39;</span><span class="p">)</span>

<span class="n">ebunch</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">path</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span>
<span class="n">edges</span> <span class="o">=</span> <span class="p">[</span><span class="n">g_phy</span><span class="o">.</span><span class="n">edge</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span> <span class="ow">in</span> <span class="n">ebunch</span><span class="p">]</span>
<span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">]</span>
<span class="n">ank_messaging</span><span class="o">.</span><span class="n">highlight</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/spf_weighted.png" /></p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[15]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">nodes</span> <span class="o">=</span> <span class="p">[</span><span class="n">n</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">graph</span><span class="p">]</span>
<span class="n">src</span> <span class="o">=</span> <span class="n">choice</span><span class="p">(</span><span class="n">nodes</span><span class="p">)</span>
<span class="n">dst</span> <span class="o">=</span> <span class="n">choice</span><span class="p">(</span><span class="n">nodes</span><span class="p">)</span>
<span class="c">#(src, dst) = (&#39;as100r1&#39;, &#39;as1r1&#39;)</span>

<span class="n">flow</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">max_flow</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">,</span> <span class="n">capacity</span> <span class="o">=</span> <span class="s">&#39;cost&#39;</span><span class="p">)</span>
<span class="k">print</span> <span class="n">flow</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stdout">
<pre>11.0
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  IP Addressing
</h2>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[16]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit.plugins.ipv4</span> <span class="kn">as</span> <span class="nn">ipv4</span>
<span class="kn">import</span> <span class="nn">autonetkit.ank</span> <span class="kn">as</span> <span class="nn">ank</span>

<span class="n">g_ipv4</span> <span class="o">=</span> <span class="n">anm</span><span class="o">.</span><span class="n">add_overlay</span><span class="p">(</span><span class="s">&quot;ipv4&quot;</span><span class="p">)</span>
<span class="n">G_in</span> <span class="o">=</span> <span class="n">anm</span><span class="p">[</span><span class="s">&#39;input&#39;</span><span class="p">]</span>
<span class="n">G_graphics</span> <span class="o">=</span> <span class="n">anm</span><span class="p">[</span><span class="s">&#39;graphics&#39;</span><span class="p">]</span>
<span class="n">G_phy</span> <span class="o">=</span> <span class="n">anm</span><span class="p">[</span><span class="s">&#39;phy&#39;</span><span class="p">]</span>

<span class="n">g_ipv4</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">G_in</span><span class="p">)</span>
<span class="n">g_ipv4</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(</span><span class="n">G_in</span><span class="o">.</span><span class="n">edges</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s">&quot;physical&quot;</span><span class="p">))</span>

<span class="n">ank</span><span class="o">.</span><span class="n">aggregate_nodes</span><span class="p">(</span><span class="n">g_ipv4</span><span class="p">,</span> <span class="n">g_ipv4</span><span class="o">.</span><span class="n">nodes</span><span class="p">(</span><span class="s">&quot;is_switch&quot;</span><span class="p">),</span> <span class="n">retain</span> <span class="o">=</span> <span class="s">&quot;edge_id&quot;</span><span class="p">)</span>

<span class="n">edges_to_split</span> <span class="o">=</span> <span class="p">[</span><span class="n">edge</span> <span class="k">for</span> <span class="n">edge</span> <span class="ow">in</span> <span class="n">g_ipv4</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span> <span class="k">if</span> <span class="n">edge</span><span class="o">.</span><span class="n">attr_both</span><span class="p">(</span><span class="s">&quot;is_l3device&quot;</span><span class="p">)]</span>
<span class="n">split_created_nodes</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">ank</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">g_ipv4</span><span class="p">,</span> <span class="n">edges_to_split</span><span class="p">,</span> <span class="n">retain</span><span class="o">=</span><span class="s">&#39;edge_id&#39;</span><span class="p">))</span>
<span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">split_created_nodes</span><span class="p">:</span>
    <span class="n">node</span><span class="p">[</span><span class="s">&#39;graphics&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">ank</span><span class="o">.</span><span class="n">neigh_average</span><span class="p">(</span><span class="n">g_ipv4</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="s">&quot;x&quot;</span><span class="p">,</span> <span class="n">G_graphics</span><span class="p">)</span>
    <span class="n">node</span><span class="p">[</span><span class="s">&#39;graphics&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">ank</span><span class="o">.</span><span class="n">neigh_average</span><span class="p">(</span><span class="n">g_ipv4</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="s">&quot;y&quot;</span><span class="p">,</span> <span class="n">G_graphics</span><span class="p">)</span>

<span class="n">g_ipv4</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">split_created_nodes</span><span class="p">,</span> <span class="n">collision_domain</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">g_ipv4</span><span class="o">.</span><span class="n">nodes</span><span class="p">(</span><span class="s">&quot;collision_domain&quot;</span><span class="p">):</span>
    <span class="n">graphics_node</span> <span class="o">=</span> <span class="n">G_graphics</span><span class="o">.</span><span class="n">node</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
    <span class="n">node</span><span class="o">.</span><span class="n">host</span> <span class="o">=</span> <span class="n">G_phy</span><span class="o">.</span><span class="n">node</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">neighbors</span><span class="p">()</span><span class="o">.</span><span class="n">next</span><span class="p">())</span><span class="o">.</span><span class="n">host</span> <span class="c"># Set host to be same as one of the neighbors (arbitrary choice)</span>
    <span class="n">asn</span> <span class="o">=</span> <span class="n">ank</span><span class="o">.</span><span class="n">neigh_most_frequent</span><span class="p">(</span><span class="n">g_ipv4</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="s">&quot;asn&quot;</span><span class="p">,</span> <span class="n">G_phy</span><span class="p">)</span> <span class="c"># arbitrary choice</span>
    <span class="n">node</span><span class="o">.</span><span class="n">asn</span> <span class="o">=</span> <span class="n">asn</span>
    <span class="n">graphics_node</span><span class="o">.</span><span class="n">asn</span> <span class="o">=</span> <span class="n">asn</span>
    <span class="n">graphics_node</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">ank</span><span class="o">.</span><span class="n">neigh_average</span><span class="p">(</span><span class="n">g_ipv4</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="s">&quot;x&quot;</span><span class="p">,</span> <span class="n">G_graphics</span><span class="p">)</span>

    <span class="n">graphics_node</span><span class="o">.</span><span class="n">device_type</span> <span class="o">=</span> <span class="s">&quot;collision_domain&quot;</span>
    <span class="n">cd_label</span> <span class="o">=</span> <span class="s">&quot;cd_&quot;</span> <span class="o">+</span> <span class="s">&quot;_&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">ank</span><span class="o">.</span><span class="n">neigh_attr</span><span class="p">(</span><span class="n">g_ipv4</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="s">&quot;label&quot;</span><span class="p">,</span> <span class="n">G_phy</span><span class="p">)))</span>
    <span class="n">node</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="n">cd_label</span> 
    <span class="n">graphics_node</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="n">cd_label</span>
    
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/ipv4.png" /></p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[17]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">ipv4</span><span class="o">.</span><span class="n">allocate_ips</span><span class="p">(</span><span class="n">g_ipv4</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stderr">
<pre><span class="ansigrey">INFO</span> Allocating Primary Host loopback IPs
<span class="ansigrey">INFO</span> Allocating Secondary Host loopback IPs
<span class="ansigrey">INFO</span> Allocating Collision Domain IPs
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/ipv4_alloc.png" /></p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[18]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit.plugins.ipv6</span> <span class="kn">as</span> <span class="nn">ipv6</span>
<span class="c"># uses the nodes and edges from ipv4</span>
<span class="n">g_ipv6</span> <span class="o">=</span> <span class="n">anm</span><span class="o">.</span><span class="n">add_overlay</span><span class="p">(</span><span class="s">&quot;ipv6&quot;</span><span class="p">)</span>
<span class="n">g_ipv4</span> <span class="o">=</span> <span class="n">anm</span><span class="p">[</span><span class="s">&#39;ipv4&#39;</span><span class="p">]</span>
<span class="n">g_ipv6</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span>
    <span class="n">g_ipv4</span><span class="p">,</span> <span class="n">retain</span><span class="o">=</span><span class="s">&quot;collision_domain&quot;</span><span class="p">)</span>  <span class="c"># retain if collision domain or not</span>
<span class="n">g_ipv6</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(</span><span class="n">g_ipv4</span><span class="o">.</span><span class="n">edges</span><span class="p">())</span>
<span class="n">ipv6</span><span class="o">.</span><span class="n">allocate_ips</span><span class="p">(</span><span class="n">g_ipv6</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">)</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stderr">
<pre><span class="ansigrey">INFO</span> Allocating Host loopback IPs
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/ipv6_alloc.png" /></p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Compiling to NIDB
</h2>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">nidb</span> <span class="o">=</span> <span class="n">autonetkit</span><span class="o">.</span><span class="n">nidb</span><span class="o">.</span><span class="n">NIDB</span><span class="p">()</span> 
<span class="n">G_phy</span> <span class="o">=</span> <span class="n">anm</span><span class="p">[</span><span class="s">&#39;phy&#39;</span><span class="p">]</span>
<span class="n">G_ip</span> <span class="o">=</span> <span class="n">anm</span><span class="p">[</span><span class="s">&#39;ipv4&#39;</span><span class="p">]</span>
<span class="n">G_graphics</span> <span class="o">=</span> <span class="n">anm</span><span class="p">[</span><span class="s">&#39;graphics&#39;</span><span class="p">]</span>

<span class="n">nidb</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">G_phy</span><span class="p">,</span> <span class="n">retain</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;label&#39;</span><span class="p">,</span> <span class="s">&#39;host&#39;</span><span class="p">,</span> <span class="s">&#39;platform&#39;</span><span class="p">,</span> <span class="s">&#39;syntax&#39;</span><span class="p">,</span> <span class="s">&#39;Network&#39;</span><span class="p">,</span> <span class="s">&#39;update&#39;</span><span class="p">])</span>

<span class="n">cd_nodes</span> <span class="o">=</span> <span class="n">G_ip</span><span class="o">.</span><span class="n">nodes</span><span class="p">(</span><span class="s">&quot;collision_domain&quot;</span><span class="p">)</span> <span class="c"># Only add created cds - otherwise overwrite host of switched</span>
<span class="n">nidb</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">cd_nodes</span><span class="p">,</span> <span class="n">retain</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;label&#39;</span><span class="p">,</span> <span class="s">&#39;host&#39;</span><span class="p">],</span> <span class="n">collision_domain</span> <span class="o">=</span> <span class="bp">True</span><span class="p">)</span>
<span class="n">edges_to_add</span> <span class="o">=</span> <span class="p">[</span><span class="n">edge</span> <span class="k">for</span> <span class="n">edge</span> <span class="ow">in</span> <span class="n">G_ip</span><span class="o">.</span><span class="n">edges</span><span class="p">()</span> <span class="k">if</span> <span class="n">edge</span><span class="o">.</span><span class="n">src</span><span class="o">.</span><span class="n">collision_domain</span> <span class="ow">or</span> <span class="n">edge</span><span class="o">.</span><span class="n">dst</span><span class="o">.</span><span class="n">collision_domain</span><span class="p">]</span>
<span class="n">nidb</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(</span><span class="n">edges_to_add</span><span class="p">,</span> <span class="n">retain</span><span class="o">=</span><span class="s">&#39;edge_id&#39;</span><span class="p">)</span>

<span class="n">nidb</span><span class="o">.</span><span class="n">copy_graphics</span><span class="p">(</span><span class="n">G_graphics</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">,</span> <span class="n">nidb</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/nidb.png" /></p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[20]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit.compiler</span>

<span class="n">anm</span><span class="o">.</span><span class="n">add_overlay</span><span class="p">(</span><span class="s">&quot;isis&quot;</span><span class="p">)</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">update_http</span><span class="p">(</span><span class="n">anm</span><span class="p">,</span> <span class="n">nidb</span><span class="p">)</span>

<span class="n">host</span> <span class="o">=</span> <span class="s">&quot;localhost&quot;</span>
<span class="n">nk_compiler</span> <span class="o">=</span> <span class="n">autonetkit</span><span class="o">.</span><span class="n">compiler</span><span class="o">.</span><span class="n">NetkitCompiler</span><span class="p">(</span><span class="n">nidb</span><span class="p">,</span> <span class="n">anm</span><span class="p">,</span> <span class="n">host</span><span class="p">)</span>
<span class="n">nk_compiler</span><span class="o">.</span><span class="n">compile</span><span class="p">()</span>
<span class="n">nidb</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stderr">
<pre><span class="ansigrey">INFO</span> Compiling Netkit for localhost
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can see the NIDB for a router, this is what gets pushed into the templates:</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[21]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">router</span> <span class="o">=</span> <span class="n">nidb</span><span class="o">.</span><span class="n">routers</span><span class="p">()</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="c"># choose a router</span>
<span class="n">router</span><span class="o">.</span><span class="n">dump</span><span class="p">()</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stdout">
<pre>{&apos;Network&apos;: None,
 &apos;_interfaces&apos;: {None: {&apos;description&apos;: &apos;loopback&apos;, &apos;type&apos;: None}},
 &apos;asn&apos;: 1,
 &apos;bgp&apos;: {&apos;debug&apos;: True,
         &apos;ebgp_neighbors&apos;: [],
         &apos;ibgp_neighbors&apos;: [{&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.3&apos;),
                             &apos;neighbor&apos;: &apos;r16&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.4&apos;),
                             &apos;neighbor&apos;: &apos;r17&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.5&apos;),
                             &apos;neighbor&apos;: &apos;r14&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.6&apos;),
                             &apos;neighbor&apos;: &apos;r15&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.7&apos;),
                             &apos;neighbor&apos;: &apos;r12&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.8&apos;),
                             &apos;neighbor&apos;: &apos;r13&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.9&apos;),
                             &apos;neighbor&apos;: &apos;r10&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.10&apos;),
                             &apos;neighbor&apos;: &apos;r11&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.18&apos;),
                             &apos;neighbor&apos;: &apos;r3&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.19&apos;),
                             &apos;neighbor&apos;: &apos;r8&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.15&apos;),
                             &apos;neighbor&apos;: &apos;r6&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.11&apos;),
                             &apos;neighbor&apos;: &apos;r18&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.12&apos;),
                             &apos;neighbor&apos;: &apos;r19&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.20&apos;),
                             &apos;neighbor&apos;: &apos;r9&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.17&apos;),
                             &apos;neighbor&apos;: &apos;r2&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.16&apos;),
                             &apos;neighbor&apos;: &apos;r1&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.14&apos;),
                             &apos;neighbor&apos;: &apos;r5&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.13&apos;),
                             &apos;neighbor&apos;: &apos;r4&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.1&apos;),
                             &apos;neighbor&apos;: &apos;r21&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False},
                            {&apos;asn&apos;: 1,
                             &apos;loopback&apos;: IPAddress(&apos;192.168.1.2&apos;),
                             &apos;neighbor&apos;: &apos;r20&apos;,
                             &apos;update_source&apos;: &apos;loopback 0&apos;,
                             &apos;use_ipv4&apos;: True,
                             &apos;use_ipv6&apos;: False}],
         &apos;ibgp_rr_clients&apos;: [],
         &apos;ibgp_rr_parents&apos;: [],
         &apos;ipv4_advertise_subnets&apos;: [IPNetwork(&apos;10.0.0.0/16&apos;)],
         &apos;ipv6_advertise_subnets&apos;: []},
 &apos;device_subtype&apos;: None,
 &apos;device_type&apos;: &apos;router&apos;,
 &apos;graphics&apos;: {&apos;device_subtype&apos;: None,
              &apos;device_type&apos;: &apos;router&apos;,
              &apos;x&apos;: 335.14050102233887,
              &apos;y&apos;: 495.67582416534424},
 &apos;host&apos;: &apos;localhost&apos;,
 &apos;input_label&apos;: &apos;r21&apos;,
 &apos;interfaces&apos;: [{&apos;_edge_id&apos;: &apos;r21_r11&apos;,
                 &apos;description&apos;: &apos;r21 to r11&apos;,
                 &apos;id&apos;: &apos;eth0&apos;,
                 &apos;ipv4_address&apos;: IPAddress(&apos;10.0.128.42&apos;),
                 &apos;ipv4_cidr&apos;: IPNetwork(&apos;10.0.128.42/30&apos;),
                 &apos;ipv4_subnet&apos;: IPNetwork(&apos;10.0.128.40/30&apos;),
                 &apos;ipv6_address&apos;: None,
                 &apos;ospf_cost&apos;: 10,
                 &apos;physical&apos;: True},
                {&apos;_edge_id&apos;: &apos;r21_r6&apos;,
                 &apos;description&apos;: &apos;r21 to r6&apos;,
                 &apos;id&apos;: &apos;eth1&apos;,
                 &apos;ipv4_address&apos;: IPAddress(&apos;10.0.0.1&apos;),
                 &apos;ipv4_cidr&apos;: IPNetwork(&apos;10.0.0.1/30&apos;),
                 &apos;ipv4_subnet&apos;: IPNetwork(&apos;10.0.0.0/30&apos;),
                 &apos;ipv6_address&apos;: None,
                 &apos;ospf_cost&apos;: 10,
                 &apos;physical&apos;: True},
                {&apos;description&apos;: &apos;Loopback&apos;,
                 &apos;id&apos;: &apos;lo0:1&apos;,
                 &apos;ipv4_address&apos;: IPAddress(&apos;192.168.1.1&apos;),
                 &apos;ipv4_subnet&apos;: IPNetwork(&apos;192.168.1.1/32&apos;)}],
 &apos;ip&apos;: {&apos;use_ipv4&apos;: True, &apos;use_ipv6&apos;: None},
 &apos;label&apos;: &apos;r21&apos;,
 &apos;loopback&apos;: IPAddress(&apos;192.168.1.1&apos;),
 &apos;loopback_subnet&apos;: IPNetwork(&apos;192.168.1.1/32&apos;),
 &apos;ospf&apos;: {&apos;lo_interface&apos;: &apos;lo0:1&apos;,
          &apos;loopback_area&apos;: 0,
          &apos;ospf_links&apos;: [{&apos;area&apos;: 0, &apos;network&apos;: IPNetwork(&apos;10.0.0.0/30&apos;)},
                         {&apos;area&apos;: 0, &apos;network&apos;: IPNetwork(&apos;10.0.128.40/30&apos;)}],
          &apos;passive_interfaces&apos;: [],
          &apos;process_id&apos;: 1},
 &apos;platform&apos;: &apos;netkit&apos;,
 &apos;render&apos;: {&apos;base&apos;: &apos;templates/quagga&apos;,
            &apos;base_dst_folder&apos;: &apos;rendered/localhost/netkit/r21&apos;,
            &apos;dst_file&apos;: &apos;r21.startup&apos;,
            &apos;dst_folder&apos;: &apos;rendered/localhost/netkit&apos;,
            &apos;template&apos;: &apos;templates/netkit_startup.mako&apos;},
 &apos;ssh&apos;: {&apos;use_key&apos;: True},
 &apos;syntax&apos;: &apos;quagga&apos;,
 &apos;tap&apos;: {&apos;id&apos;: &apos;eth2&apos;, &apos;ip&apos;: IPAddress(&apos;172.16.0.22&apos;)},
 &apos;update&apos;: None,
 &apos;x&apos;: 340.0,
 &apos;y&apos;: 590.0,
 &apos;zebra&apos;: {&apos;hostname&apos;: &apos;r21&apos;, &apos;password&apos;: &apos;1234&apos;, &apos;static_routes&apos;: []}}
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  AutoNetkit Configuration Generation Process
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>The Render module pushes the NIDB into the specified template(s), creating device configuration files.</p>
<p><img alt="" src="files/images/flowchart_nidb.png" /></p>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Rendering to Templates
</h2>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[22]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit.render</span>
<span class="n">autonetkit</span><span class="o">.</span><span class="n">render</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">nidb</span><span class="p">)</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stderr">
<pre><span class="ansigrey">INFO</span> Rendering Network
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[23]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<span class="n">dst_folder</span> <span class="o">=</span> <span class="n">nidb</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="s">&#39;localhost&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">render_dst_folder</span>
<span class="n">walked</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">dst_folder</span><span class="p">)</span>
<span class="k">for</span> <span class="n">path</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">walked</span><span class="p">)[:</span><span class="mi">10</span><span class="p">]:</span> <span class="c"># first ten dirs</span>
  <span class="k">print</span> <span class="n">path</span>
  <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span><span class="p">[:</span><span class="mi">10</span><span class="p">]:</span> <span class="c"># first ten files</span>
    <span class="k">print</span> <span class="s">&quot;</span><span class="se">\t</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">f</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stdout">
<pre>rendered/localhost/netkit
	lab.conf
	r1.startup
	r10.startup
	r11.startup
	r12.startup
	r13.startup
	r14.startup
	r15.startup
	r16.startup
	r17.startup
rendered/localhost/netkit/r1
rendered/localhost/netkit/r1/etc
	hostname
	shadow
rendered/localhost/netkit/r1/etc/ssh
	sshd_config
rendered/localhost/netkit/r1/etc/zebra
	bgpd.conf
	daemons
	isisd.conf
	motd.txt
	ospfd.conf
	zebra.conf
rendered/localhost/netkit/r1/root
rendered/localhost/netkit/r1/root/.ssh
	authorized_keys
rendered/localhost/netkit/r10
rendered/localhost/netkit/r10/etc
	hostname
	shadow
rendered/localhost/netkit/r10/etc/ssh
	sshd_config
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>We can see the config files for a router:</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[24]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">router</span> <span class="o">=</span> <span class="n">nidb</span><span class="o">.</span><span class="n">routers</span><span class="p">()</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="c"># choose a router</span>
<span class="n">zebra_dir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">router</span><span class="o">.</span><span class="n">render</span><span class="o">.</span><span class="n">base_dst_folder</span><span class="p">,</span> <span class="s">&quot;etc&quot;</span><span class="p">,</span> <span class="s">&quot;zebra&quot;</span><span class="p">)</span>

<span class="n">ospfd_conf</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">zebra_dir</span><span class="p">,</span> <span class="s">&quot;ospfd.conf&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">ospfd_conf</span><span class="p">,</span> <span class="s">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
    <span class="k">print</span> <span class="n">fh</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stdout">
<pre>hostname r21
password 1234   
banner motd file /etc/quagga/motd.txt
!
  interface eth0
  #Link to r21 to r11
  ip ospf cost 10
  !
  interface eth1
  #Link to r21 to r6
  ip ospf cost 10
  !
!
router ospf
  network 10.0.0.0/30 area 0 
  network 10.0.128.40/30 area 0 
  !
  !
  network 192.168.1.1/32 area 0
!

</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[25]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">bgpd_conf</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">zebra_dir</span><span class="p">,</span> <span class="s">&quot;bgpd.conf&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">bgpd_conf</span><span class="p">,</span> <span class="s">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
    <span class="k">print</span> <span class="n">fh</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stdout">
<pre>!
hostname r21
password 1234              
banner motd file /etc/quagga/motd.txt
!enable password 1234
!
  router bgp 1   
  bgp router-id 192.168.1.1
  no synchronization
  network 10.0.0.0/16
! ibgp
  ! ibgp peers
  ! r16
  neighbor 192.168.1.3 remote-as 1
  neighbor 192.168.1.3 update-source 192.168.1.1                                                     
  neighbor 192.168.1.3 send-community      
  neighbor 192.168.1.3 next-hop-self
  ! r17
  neighbor 192.168.1.4 remote-as 1
  neighbor 192.168.1.4 update-source 192.168.1.1                                                     
  neighbor 192.168.1.4 send-community      
  neighbor 192.168.1.4 next-hop-self
  ! r14
  neighbor 192.168.1.5 remote-as 1
  neighbor 192.168.1.5 update-source 192.168.1.1                                                     
  neighbor 192.168.1.5 send-community      
  neighbor 192.168.1.5 next-hop-self
  ! r15
  neighbor 192.168.1.6 remote-as 1
  neighbor 192.168.1.6 update-source 192.168.1.1                                                     
  neighbor 192.168.1.6 send-community      
  neighbor 192.168.1.6 next-hop-self
  ! r12
  neighbor 192.168.1.7 remote-as 1
  neighbor 192.168.1.7 update-source 192.168.1.1                                                     
  neighbor 192.168.1.7 send-community      
  neighbor 192.168.1.7 next-hop-self
  ! r13
  neighbor 192.168.1.8 remote-as 1
  neighbor 192.168.1.8 update-source 192.168.1.1                                                     
  neighbor 192.168.1.8 send-community      
  neighbor 192.168.1.8 next-hop-self
  ! r10
  neighbor 192.168.1.9 remote-as 1
  neighbor 192.168.1.9 update-source 192.168.1.1                                                     
  neighbor 192.168.1.9 send-community      
  neighbor 192.168.1.9 next-hop-self
  ! r11
  neighbor 192.168.1.10 remote-as 1
  neighbor 192.168.1.10 update-source 192.168.1.1                                                     
  neighbor 192.168.1.10 send-community      
  neighbor 192.168.1.10 next-hop-self
  ! r3
  neighbor 192.168.1.18 remote-as 1
  neighbor 192.168.1.18 update-source 192.168.1.1                                                     
  neighbor 192.168.1.18 send-community      
  neighbor 192.168.1.18 next-hop-self
  ! r8
  neighbor 192.168.1.19 remote-as 1
  neighbor 192.168.1.19 update-source 192.168.1.1                                                     
  neighbor 192.168.1.19 send-community      
  neighbor 192.168.1.19 next-hop-self
  ! r6
  neighbor 192.168.1.15 remote-as 1
  neighbor 192.168.1.15 update-source 192.168.1.1                                                     
  neighbor 192.168.1.15 send-community      
  neighbor 192.168.1.15 next-hop-self
  ! r18
  neighbor 192.168.1.11 remote-as 1
  neighbor 192.168.1.11 update-source 192.168.1.1                                                     
  neighbor 192.168.1.11 send-community      
  neighbor 192.168.1.11 next-hop-self
  ! r19
  neighbor 192.168.1.12 remote-as 1
  neighbor 192.168.1.12 update-source 192.168.1.1                                                     
  neighbor 192.168.1.12 send-community      
  neighbor 192.168.1.12 next-hop-self
  ! r9
  neighbor 192.168.1.20 remote-as 1
  neighbor 192.168.1.20 update-source 192.168.1.1                                                     
  neighbor 192.168.1.20 send-community      
  neighbor 192.168.1.20 next-hop-self
  ! r2
  neighbor 192.168.1.17 remote-as 1
  neighbor 192.168.1.17 update-source 192.168.1.1                                                     
  neighbor 192.168.1.17 send-community      
  neighbor 192.168.1.17 next-hop-self
  ! r1
  neighbor 192.168.1.16 remote-as 1
  neighbor 192.168.1.16 update-source 192.168.1.1                                                     
  neighbor 192.168.1.16 send-community      
  neighbor 192.168.1.16 next-hop-self
  ! r5
  neighbor 192.168.1.14 remote-as 1
  neighbor 192.168.1.14 update-source 192.168.1.1                                                     
  neighbor 192.168.1.14 send-community      
  neighbor 192.168.1.14 next-hop-self
  ! r4
  neighbor 192.168.1.13 remote-as 1
  neighbor 192.168.1.13 update-source 192.168.1.1                                                     
  neighbor 192.168.1.13 send-community      
  neighbor 192.168.1.13 next-hop-self
  ! r21
  neighbor 192.168.1.1 remote-as 1
  neighbor 192.168.1.1 update-source 192.168.1.1                                                     
  neighbor 192.168.1.1 send-community      
  neighbor 192.168.1.1 next-hop-self
  ! r20
  neighbor 192.168.1.2 remote-as 1
  neighbor 192.168.1.2 update-source 192.168.1.1                                                     
  neighbor 192.168.1.2 send-community      
  neighbor 192.168.1.2 next-hop-self
! ebgp

debug bgp
debug bgp events
debug bgp filters
debug bgp fsm
debug bgp keepalives
debug bgp updates 
log file /var/log/zebra/bgpd.log

</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Deploying to Netkit Host
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>The deployment has a number of requirements:</p>
<ol>
<li>Netkit (available at <a href="netkit.org">netkit.org</a>) installed (download and installation instructions available <a href="http://wiki.netkit.org/index.php/Download_Official">here</a>).</li>
<li>SSH keys configured for remote server (AutoNetkit currently uses SSH to deploy to the server - you can use the localhost through SSH for now)</li>
<li>
<p>A virtual machine created for the TAP Interface:</p>
<p>vstart taptunnelvm --con0=none --eth0=tap,172.16.0.1,172.16.0.2</p>
</li>
</ol>
<p>(this will require sudo access on the Netkit host)</p>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[21]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="n">username</span> <span class="o">=</span> <span class="s">&quot;sk2&quot;</span>
<span class="n">host</span> <span class="o">=</span> <span class="s">&quot;192.168.255.129&quot;</span>

<span class="kn">import</span> <span class="nn">autonetkit.deploy.netkit</span> <span class="kn">as</span> <span class="nn">nk_deploy</span>
<span class="n">dst_folder</span> <span class="o">=</span> <span class="n">nidb</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="s">&#39;localhost&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">render_dst_folder</span>
<span class="n">nk_deploy</span><span class="o">.</span><span class="n">deploy</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">dst_folder</span><span class="p">)</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stderr">
<pre><span class="ansigrey">INFO</span> Packaging rendered/localhost/netkit
<span class="ansigrey">INFO</span> Transferring Netkit lab
<span class="ansigrey">INFO</span> Connecting to 192.168.255.129 with sk2
<span class="ansigrey">INFO</span> Extracting and starting Netkit lab
<span class="ansigrey">INFO</span> Starting lab
<span class="ansigrey">INFO</span> Starting &quot;r1&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r3&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r4&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r2&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r5&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r6&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r8&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r9&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r10&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r11&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r12&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r13&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r14&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r15&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r16&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r17&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r18&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r19&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r20&quot;...
<span class="ansigrey">INFO</span> Starting &quot;r21&quot;...
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<h2>
  Measurement
</h2>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p>Measure requires a remote host to be setup, and rabbitmq running, (by default ank will look on localhost)
 http://www.rabbitmq.com/install-debian.html</p>
<p>or for OS X: http://superuser.com/questions/464311/open-port-5672-tcp-for-access-to-rabbitmq-on-mac</p>
<p>and</p>
<pre><code> pip install pika
 pip install https://github.com/knipknap/exscript/tarball/master
</code></pre>
<p>note this needs paramiko... which needs to compile. if you don't have python headers, eg in ubuntu: </p>
<pre><code>sudo apt-get install python-dev

wget https://raw.github.com/sk2/autonetkit/master/autonetkit/measure_client.py

$ python measure_client.py --server 192.168.255.1
</code></pre>
<p>where --server specifies the rabbitmq server</p>
<p>can also use through ANK package:
 install ank through github, then install Exscript</p>
<p>Can then run the below measurement commands</p>
<pre><code>$ ank_measure_client --server 192.168.129.1
</code></pre>
</div>
<div class="cell border-box-sizing code_cell vbox">
<div class="input hbox">
<div class="prompt input_prompt">In&nbsp;[25]:</div>
<div class="input_area box-flex1">
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">autonetkit.measure</span> <span class="kn">as</span> <span class="nn">measure</span>
<span class="kn">import</span> <span class="nn">random</span>

<span class="n">remote_hosts</span> <span class="o">=</span> <span class="p">[</span><span class="n">node</span><span class="o">.</span><span class="n">tap</span><span class="o">.</span><span class="n">ip</span> <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">nidb</span><span class="o">.</span><span class="n">routers</span><span class="p">()</span> <span class="p">]</span>

<span class="n">dest_node</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">nidb</span><span class="o">.</span><span class="n">routers</span><span class="p">()))</span>

<span class="n">dest_ip</span> <span class="o">=</span> <span class="n">dest_node</span><span class="o">.</span><span class="n">interfaces</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">ipv4_address</span> <span class="c"># choose random interface on this node</span>
<span class="n">command</span> <span class="o">=</span> <span class="s">&quot;traceroute -n -a -U -w 0.5 </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">dest_ip</span> 

<span class="n">measure</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">nidb</span><span class="p">,</span> <span class="n">command</span><span class="p">,</span> <span class="n">remote_hosts</span><span class="p">)</span>
</pre></div>

</div>
</div>
<div class="vbox output_wrapper">
<div class="output vbox">
<div class="hbox output_area">
<div class="prompt output_prompt"></div>
<div class="output_subarea output_stream output_stderr">
<pre><span class="ansigrey">INFO</span> Trace from r21 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.128.41  5 ms
 2  10.0.128.38  4 ms
r21:~# &apos;
<span class="ansigrey">INFO</span> [r21, r11, r16]
<span class="ansigrey">INFO</span> Trace from r16 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.128.38  0 ms
r16:~# &apos;
<span class="ansigrey">INFO</span> [r16, r16]
<span class="ansigrey">INFO</span> Trace from r20 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.13  2 ms
 2  10.0.0.42  1 ms
 3  10.0.0.26  1 ms
 4  10.0.0.38  1 ms
 5  10.0.128.53  1 ms
 6  10.0.0.6  2 ms
 7  10.0.128.34  2 ms
 8  10.0.128.38  2 ms
r20:~# &apos;
<span class="ansigrey">INFO</span> [r20, r12, r5, r9, r18, r17, r14, r2, r16]
<span class="ansigrey">INFO</span> Trace from r17 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.6  3 ms
 2  10.0.128.34  1 ms
 3  10.0.128.38  2 ms
r17:~# &apos;
<span class="ansigrey">INFO</span> [r17, r14, r2, r16]
<span class="ansigrey">INFO</span> Trace from r14 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.62  0 ms
 2  10.0.128.38  1 ms
r14:~# &apos;
<span class="ansigrey">INFO</span> [r14, r15, r16]
<span class="ansigrey">INFO</span> Trace from r12 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.42  2 ms
 2  10.0.0.26  3 ms
 3  10.0.0.38  4 ms
 4  10.0.128.53  4 ms
 5  10.0.0.6  1 ms
 6  10.0.0.62  1 ms
 7  10.0.128.38  1 ms
r12:~# &apos;
<span class="ansigrey">INFO</span> [r12, r5, r9, r18, r17, r14, r15, r16]
<span class="ansigrey">INFO</span> Trace from r15 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.128.38  1 ms
r15:~# &apos;
<span class="ansigrey">INFO</span> [r15, r16]
<span class="ansigrey">INFO</span> Trace from r13 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.128.14  1 ms
 2  10.0.0.38  1 ms
 3  10.0.128.53  1 ms
 4  10.0.0.6  3 ms
 5  10.0.128.34  1 ms
 6  10.0.128.38  1 ms
r13:~# &apos;
<span class="ansigrey">INFO</span> [r13, r9, r18, r17, r14, r2, r16]
<span class="ansigrey">INFO</span> Trace from r11 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.128.38  1 ms
r11:~# &apos;
<span class="ansigrey">INFO</span> [r11, r16]
<span class="ansigrey">INFO</span> Trace from r10 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.58  1 ms
 2  10.0.0.62  1 ms
 3  10.0.128.38  1 ms
r10:~# &apos;
<span class="ansigrey">INFO</span> [r10, r14, r15, r16]
<span class="ansigrey">INFO</span> Trace from r19 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.54  0 ms
 2  10.0.128.53  0 ms
 3  10.0.0.6  1 ms
 4  10.0.128.34  1 ms
 5  10.0.128.38  1 ms
r19:~# &apos;
<span class="ansigrey">INFO</span> [r19, r18, r17, r14, r2, r16]
<span class="ansigrey">INFO</span> Trace from r4 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.22  1 ms
 2  10.0.0.38  1 ms
 3  10.0.128.53  1 ms
 4  10.0.0.6  1 ms
 5  10.0.0.62  1 ms
 6  10.0.128.38  1 ms
r4:~# &apos;
<span class="ansigrey">INFO</span> [r4, r9, r18, r17, r14, r15, r16]
<span class="ansigrey">INFO</span> Trace from r5 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.26  1 ms
 2  10.0.0.38  1 ms
 3  10.0.128.53  3 ms
 4  10.0.0.6  3 ms
 5  10.0.128.34  2 ms
 6  10.0.128.38  2 ms
r5:~# &apos;
<span class="ansigrey">INFO</span> [r5, r9, r18, r17, r14, r2, r16]
<span class="ansigrey">INFO</span> Trace from r18 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.128.53  0 ms
 2  10.0.0.6  4 ms
 3  10.0.0.62  1 ms
 4  10.0.128.38  2 ms
r18:~# &apos;
<span class="ansigrey">INFO</span> [r18, r17, r14, r15, r16]
<span class="ansigrey">INFO</span> Trace from r1 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.34  2 ms
 2  10.0.128.38  1 ms
r1:~# &apos;
<span class="ansigrey">INFO</span> [r1, r2, r16]
<span class="ansigrey">INFO</span> Trace from r6 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.128.18  4 ms
 2  10.0.0.22  2 ms
 3  10.0.0.38  2 ms
 4  10.0.128.53  1 ms
 5  10.0.0.6  2 ms
 6  10.0.128.34  1 ms
 7  10.0.128.38  1 ms
r6:~# &apos;
<span class="ansigrey">INFO</span> [r6, r4, r9, r18, r17, r14, r2, r16]
<span class="ansigrey">INFO</span> Trace from r3 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.18  1 ms
 2  10.0.0.34  1 ms
 3  10.0.128.38  1 ms
r3:~# &apos;
<span class="ansigrey">INFO</span> [r3, r1, r2, r16]
<span class="ansigrey">INFO</span> Trace from r8 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.45  1 ms
 2  10.0.0.13  1 ms
 3  10.0.0.42  1 ms
 4  10.0.0.26  1 ms
 5  10.0.0.38  1 ms
 6  10.0.128.53  1 ms
 7  10.0.0.6  1 ms
 8  10.0.0.62  1 ms
 9  10.0.128.38  2 ms
r8:~# &apos;
<span class="ansigrey">INFO</span> [r8, r20, r12, r5, r9, r18, r17, r14, r15, r16]
<span class="ansigrey">INFO</span> Trace from r2 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.128.38  2 ms
r2:~# &apos;
<span class="ansigrey">INFO</span> [r2, r16]
<span class="ansigrey">INFO</span> Trace from r9 to r16
<span class="ansigrey">INFO</span> &apos;traceroute -n -a -U -w 0.5 10.0.128.38
traceroute to 10.0.128.38 (10.0.128.38), 64 hops max, 40 byte packets
 1  10.0.0.38  2 ms
 2  10.0.128.53  1 ms
 3  10.0.0.6  0 ms
 4  10.0.128.34  1 ms
 5  10.0.128.38  1 ms
r9:~# &apos;
<span class="ansigrey">INFO</span> [r9, r18, r17, r14, r2, r16]
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="text_cell_render border-box-sizing rendered_html">
<p><img alt="" src="files/images/traceroute.png" /></p>
</div>
</body>
</html>